package org.bai.meetingfilm.backend.common.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.bai.meetingfilm.common.vo.BasePageRepVO;

/**
 * @ClassName PageUtil
 * @Description 分页封装工具
 * @Author bai
 * @Date 2021/7/18 19:40
 * @Version 1.0
 **/
public class PageUtil<M> {

    /**
     * @param: iPage mybatis-plus分页对象
     * @description: 将 mybatis-plus 的分页信息转换为通用定义分页对象
     * @return: {@link BasePageRepVO<M> }
     * @author: bai
     * @date: 2021/7/18 19:43
     */
    public static<M> BasePageRepVO<M> buildBasePageRepVO(IPage<M> iPage) {
        if (null == iPage) {
            return BasePageRepVO.buildDefaultPage();
        }

        BasePageRepVO<M> pageRepVO = new BasePageRepVO<>();
        pageRepVO.setTotalSize(iPage.getTotal());
        pageRepVO.setTotalPages(iPage.getPages());
        pageRepVO.setPageSize(iPage.getSize());
        pageRepVO.setNowPage(iPage.getCurrent());
        pageRepVO.setList(iPage.getRecords());
        return pageRepVO;
    }
}
